﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TelecoSystems.Infrastructure.Helpers;

namespace TelecoSystems.Tests
{
    [TestClass]
    public class ConvertersTests
    {
        BoolToVisibilityConverter boolToVisibilityConverter;
        GenderToBoolConverter genderToBoolConverter;

        public ConvertersTests()
        {
            boolToVisibilityConverter = new BoolToVisibilityConverter();
            genderToBoolConverter = new GenderToBoolConverter();
        }

        [TestMethod]
        [Description("Tests correct BoolToVisibilityConverter Convert() work")]
        public void TestCorrectBTVConvert()
        {
            Assert.IsNotNull(boolToVisibilityConverter, "BoolToVisiblityConverter cannot be null.");

            Assert.IsInstanceOfType(boolToVisibilityConverter.Convert(true, typeof(bool), null, null), typeof(Visibility), "Converted value should be of type Visiblity.");
            Assert.AreEqual(Visibility.Visible, (Visibility)boolToVisibilityConverter.Convert(true, typeof(bool), null, null), "Converted value should be visible (from true).");

            Assert.IsInstanceOfType(boolToVisibilityConverter.Convert(false, typeof(bool), null, null), typeof(Visibility), "Converted value should be of type Visiblity.");
            Assert.AreEqual(Visibility.Collapsed, (Visibility)boolToVisibilityConverter.Convert(false, typeof(bool), null, null), "Converted value should be collapsed (from false).");
        }

        [TestMethod]
        [Description("Tests correct BoolToVisibilityConverter ConvertBack() work")]
        public void TestCorrectBTVConvertBack()
        {            
            Assert.IsInstanceOfType(boolToVisibilityConverter.ConvertBack(Visibility.Visible, typeof(Visibility), null, null), typeof(bool), "Converted value should be of type bool.");
            Assert.AreEqual(true, (bool)boolToVisibilityConverter.ConvertBack(Visibility.Visible, typeof(Visibility), null, null), "Converted value should be true (from visible).");            

            Assert.IsInstanceOfType(boolToVisibilityConverter.ConvertBack(Visibility.Collapsed, typeof(Visibility), null, null), typeof(bool), "Converted value should be of type bool.");
            Assert.AreEqual(false, (bool)boolToVisibilityConverter.ConvertBack(Visibility.Collapsed, typeof(Visibility), null, null), "Converted value should be false (from collapsed).");
        }

        [TestMethod]
        [Description("Tests correct GenderToBoolConverter Convert() work")]
        public void TestCorrectGTBConvert()
        {
            Assert.IsNotNull(genderToBoolConverter, "GenderToBoolConverter cannot be null.");

            Assert.AreEqual(true, (bool)genderToBoolConverter.Convert("M", typeof(bool), "M", null), "M = M, should be true.");
            Assert.AreEqual(false, (bool)genderToBoolConverter.Convert("M", typeof(bool), "F", null), "M != F, should be false.");
        }

        [TestMethod]
        [Description("Tests correct GenderToBoolConverter ConvertBack() work")]
        public void TestCorrectGTBConvertBack()
        {
            Assert.AreEqual("M", (string)genderToBoolConverter.ConvertBack(true, typeof(string), "M", null), "M is true, should return M.");
            Assert.AreEqual("F", (string)genderToBoolConverter.ConvertBack(false, typeof(string), "M", null), "M is false, should return F.");
            Assert.AreEqual("F", (string)genderToBoolConverter.ConvertBack(true, typeof(string), "F", null), "F is true, should return F.");
            Assert.AreNotEqual("F", (string)genderToBoolConverter.ConvertBack(false, typeof(string), "F", null), "F is false, should not return F.");
        }
    }
}
